#include <bits/stdc++.h>
using namespace std;
int F[10000 + 5];
struct Edge
{
    int from, to, dist;
}edges[100000 + 5];
int cur = 0;

// 从大到小排序
bool compare(const Edge &lhs, const Edge &rhs)
{
    return lhs.dist > rhs.dist;
}
int ufind(int x) {return x == F[x] ? x : F[x] = ufind(F[x]);}
int main()
{
#ifdef LOCAL
    freopen("PREV-22.in", "r", stdin);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    int m, n; cin >> n >> m;
    for(int i = 1; i <= n; ++i) F[i] = i;
    for(cur = 0; cur < m; cur++)
        cin >> edges[cur].from >> edges[cur].to >> edges[cur].dist; 
    sort(edges, edges + cur, compare);
    int pre = -1, ans = 0;
    for(int i = 0; i < cur; ++i)
    {
        int u = ufind(edges[i].from), v = ufind(edges[i].to);
        // cout << edges[i].from << "   " << edges[i].to << "   " << u << "  "  << v << endl;
            
        if(u == v) continue;
        F[u] = v;                   // 合并
        if(pre != edges[i].dist)
        {
            ans++;
            pre = edges[i].dist;
        }
    }    
    cout << ans << endl;
    return 0;
}